package com.soundplus.app.shp04.Activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.sppmode.Common.AllParam;
import com.example.sppmode.Common.DataConfig;
import com.soundplus.app.shp04.Common.FuncListItem;
import com.soundplus.app.shp04.Common.FuncListAdapter;
import com.soundplus.app.shp04.DeviceConnectMgr.DevConnMgr;
import com.soundplus.app.shp04.R;
import com.soundplus.app.shp04.databinding.ActivitySettingBinding;

import java.util.ArrayList;
import java.util.List;

public class SettingActivity extends AppCompatActivity {

    private Context context;
    private ActivitySettingBinding binding;
    private FuncListAdapter funcListAdapter;
    private List<FuncListItem> funcListItemList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        context = this;
        binding = ActivitySettingBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        initView();
    }

    private void initView() {
        funcListItemList.clear();
        if(AllParam.getConnProtocolType() == DevConnMgr.CONN_PROTOCOL_BLE)
            funcListItemList.add(new FuncListItem(getString(R.string.scanned_device), null, null, LeDeviceScanActivity.class, true));
        else if(AllParam.getConnProtocolType() == DataConfig.CONN_PROTOCOL_SPP)
            funcListItemList.add(new FuncListItem(getString(R.string.scanned_device), null, null, SppDeviceScanActivity.class, true));
        funcListItemList.add(new FuncListItem(getString(R.string.paired_dev_list), null, null, PairedDevListActivity.class, true));
        funcListItemList.add(new FuncListItem(getString(R.string.restore_default), null, null, RestoreDefaultActivity.class, true));
        funcListItemList.add(new FuncListItem(getString(R.string.app_info), null, null, AppInfoActivity.class, true));

        funcListAdapter = new FuncListAdapter(context, funcListItemList);
        binding.lvSettingMenu.setAdapter(funcListAdapter);
        binding.lvSettingMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Class<?> cls = funcListItemList.get(i).getExecCls();
                if (cls != null) {
                    Intent intent = new Intent(SettingActivity.this, cls);
                    startActivity(intent);
                }
            }
        });
    }
}

